<%@ page import="java.util.Date" %>
<%@ page contentType="text/html;charset=UTF-8" %>
<%@ include file="../include/tag.jsp" %>
<!DOCTYPE html>
<html lang="zh">
<head>
    <title>众筹审核</title>
    <%@include file="../include/commonFile.jsp" %>
    <link rel="stylesheet" href="${ctx}/css/common/list.css">
    <link rel="stylesheet" href="${ctx}/css/common/table.css">
</head>
<body>
<!--头部-->
<%@include file="../include/header.jsp" %>
<div class="index-outside">
    <%@include file="../include/sidebar.jsp" %>
    <!--内容-->
    <section>
        <div class="section-main">
            <form class="layui-form" action="${ctx}/crowdfund/event/checkList.do" id="myForm" method="post">
                <input type="hidden" name="pageNo" id="pageNo"/>
                <div class="f-search-bar">
                    <div class="search-container">
                        <ul class="search-form-content">
                            <li class="form-item-inline"><label class="search-form-lable">主题名称</label>
                                <div class="layui-input-inline">
                                    <input type="text" name="name" autocomplete="off" class="layui-input"
                                           value="${event.name}" placeholder="请输入主题名称">
                                </div>
                            </li>
                            <li class="form-item-inline"><label class="search-form-lable">发布者</label>
                                <div class="layui-input-inline">
                                    <input type="text" name="memberName" autocomplete="off" class="layui-input"
                                           value="${input.memberName}" placeholder="请输入发布者">
                                </div>
                            </li>
                            <li class="form-item-inline"><label class="search-form-lable">主题状态</label>
                                <div class="layui-input-inline">
                                    <select name="progress">
                                        <option value="">全部</option>
                                        <option value="1" ${event.progress == 1 ? 'selected' : ''}>进行中</option>
                                        <option value="2" ${event.progress == 2 ? 'selected' : ''}>已截止</option>
                                    </select>
                                </div>
                            </li>

                            <li class="form-item-inline"><label class="search-form-lable">审核状态</label>
                                <div class="layui-input-inline">
                                    <select name="checkStatus">
                                        <option value="">全部</option>
                                        <option value="0" ${event.checkStatus == 0 ? 'selected' : ''}>待审核</option>
                                        <option value="1" ${event.checkStatus == 1 ? 'selected' : ''}>审核通过</option>
                                        <option value="2" ${event.checkStatus == 2 ? 'selected' : ''}>已拒绝</option>
                                    </select>
                                </div>
                            </li>

                            <li class="form-item-inline"><label class="search-form-lable">合作商类型</label>
                                <div class="layui-input-inline">
                                    <select name="partnerType">
                                        <option value="">全部</option>
                                        <option value="0" ${event.partnerType == 0 ? 'selected="selected"' : ''}>系统客户
                                        </option>
                                        <option value="1" ${event.partnerType == 1 ? 'selected="selected"' : ''}>大客户
                                        </option>
                                        <option value="2" ${event.partnerType == 2 ? 'selected="selected"' : ''}>地接客户
                                        </option>
                                        <option value="3" ${event.partnerType == 3 ? 'selected="selected"' : ''}>运营客户
                                        </option>
                                        <option value="4" ${event.partnerType == 4 ? 'selected="selected"' : ''}>注册客户
                                        </option>
                                    </select>
                                </div>
                            </li>
                        </ul>
                        <ul class="search-form-content">
                            <li class="form-item"><label class="search-form-lable">发布时间</label>
                                <div class="check-btn-inner" id="timeType">
                                    <a id="all" href="javascript:void(0);"
                                       onclick="setTimeType($(this),0,'#myForm')" ${empty input.timeType || input.timeType == 0 ? 'class="active"' : ''}>全部</a>
                                    <a href="javascript:void(0);"
                                       onclick="setTimeType($(this),1,'#myForm')" ${input.timeType == 1 ? 'class="active"' : ''}>今天</a>
                                    <a href="javascript:void(0);"
                                       onclick="setTimeType($(this),2,'#myForm')" ${input.timeType == 2 ? 'class="active"' : ''}>本周内</a>
                                    <a href="javascript:void(0);"
                                       onclick="setTimeType($(this),3,'#myForm')" ${input.timeType == 3 ? 'class="active"' : ''}>本月内</a>
                                    <input type="hidden" name="timeType" value="${input.timeType}"/>
                                </div>
                                <div class="layui-inline">
                                    <div class="layui-input-inline">
                                        <input class="layui-input" type="text" name="createStart"
                                               value="${input.createStart}" placeholder="开始日">
                                    </div>
                                    -
                                    <div class="layui-input-inline">
                                        <input class="layui-input" type="text" name="createEnd"
                                               value="${input.createEnd}" placeholder="截止日">
                                    </div>
                                </div>
                            </li>
                            <li class="form-item-inline">
                                <div class="sub-btns">
                                    <a class="layui-btn layui-btn-danger"
                                       href="javascript:submitFunction('#myForm')">查询</a>
                                    <a class="layui-btn layui-btn-normal"
                                       href="javascript:resetFunction('#myForm')">重置</a>
                                </div>
                            </li>
                        </ul>
                    </div>
                </div>
            </form>
            <div class="list-content">
                <ul class="num mt10">
                    <div class="l">
                        <li class="f16">共<span class="red">${page.totalCount}</span>条数据</li>
                    </div>
                    <p class="cl"></p>
                </ul>
                <div class="cl">
                    <table class="layui-table">
                        <colgroup>
                            <col width="80px">
                            <col width="20%">
                            <col width="15%">
                            <col width="120px">
                            <col width="150px">
                            <col width="120px">
                            <col width="150px">
                        </colgroup>
                        <thead>
                        <tr>
                            <th>排列号</th>
                            <th>主题名称</th>
                            <th>发布者</th>
                            <th>合作商类型</th>
                            <th>发布时间</th>
                            <th>审核状态</th>
                            <th>操 作</th>
                        </tr>
                        </thead>
                        <tbody>
                        <c:set var="nowDate" value="<%=new Date()%>"></c:set>
                        <c:forEach var="event" items="${list}" varStatus="st">
                            <tr>
                                <td>
                                    <c:set var="rowNo" value="${st.count + ((page.page - 1) * page.limit)}"/>
                                    <c:if test="${rowNo < 10}">0${rowNo}</c:if>
                                    <c:if test="${rowNo >= 10}">${rowNo}</c:if>
                                </td>
                                <td class="ellipsis-1 tl" title="${event.name}">
                                    <a href="${ctx}/crowdfund/event/eventDetail.do?eventId=${event.id}">${event.name}</a>
                                </td>
                                <td class="table-member"
                                    onclick="openDialogShow('用户名片','${ctx}/system/member/memberView.do?id=${event.createBy}','400px','470px')">
                                    <div class="member-cell">
                                        <div class="member-logo common-img">
                                            <img src="<c:if test="${event.logo != null}">${event.logo}?imageMogr2/auto-orient/crop/126x126</c:if>"
                                                 alt="" onerror="txz.errImg(this)" onload="txz.imgLoad(this)">
                                        </div>
                                        <div class="member-name ellipsis-1">
                                            <a class="blue" title="${event.realname}"
                                               href="javascript:void(0);">${event.realname}</a>
                                        </div>
                                    </div>
                                </td>
                                <td>
                                    <c:choose>
                                        <c:when test="${empty event.partnerType || event.partnerType == 0}">
                                            系统客户
                                        </c:when>
                                        <c:when test="${not empty event.partnerType && event.partnerType == 1}">
                                            <span class="green">大客户</span>
                                        </c:when>
                                        <c:when test="${not empty event.partnerType && event.partnerType == 2}">
                                            <span style="color: coral">地接客户</span>
                                        </c:when>
                                        <c:when test="${not empty event.partnerType && event.partnerType == 3}">
                                            <span style="color: darkolivegreen">运营客户</span>
                                        </c:when>
                                        <c:when test="${not empty event.partnerType && event.partnerType == 4}">
                                            <span style="color: darkolivegreen">注册客户</span>
                                        </c:when>
                                    </c:choose>
                                </td>
                                <td><fmt:formatDate value="${event.createDate}" pattern="yyyy-MM-dd HH:mm:ss"/></td>
                                <td title="<c:if test="${event.checkStatus==2}">${event.checkRemark}</c:if>">
                                    <c:choose>
                                        <c:when test="${event.checkStatus==0}">待审核</c:when>
                                        <c:when test="${event.checkStatus==1}">
                                            <span style="color: green;">审核通过</span>
                                        </c:when>
                                        <c:when test="${event.checkStatus==2}">
                                           <span><a href="javascript:showAuthor1('${event.checkRemark}')"
                                                    class="red">已拒绝&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<font
                                                   style="color: #5e5e5e">▼</font></a> </span>
                                        </c:when>
                                    </c:choose>
                                </td>
                                <td class="tb-opts">
                                    <div class="comm-opts">
                                        <c:if test="${event.checkStatus==0}">
                                            <a href="javascript:passThisEvent('${event.id}','${event.partnerType}');" class="green">通过</a>
                                            <a href="javascript:refuseThisEvent('${event.id}');" class="red">拒绝</a>
                                        </c:if>
                                        <c:if test="${event.checkStatus==1 and (event.partnerType == 0 || event.partnerType == 4) }">
                                            <a href="javascript:showAuthor2('${event.serviceCharge}')"
                                               >查看担保金</a>
                                        </c:if>
                                    </div>
                                </td>
                            </tr>
                        </c:forEach>
                        </tbody>
                    </table>
                </div>
            </div>
            <div id="page_content" class="page-container"></div>
        </div><!--底部-->
        <%@include file="../include/footer.jsp" %>
    </section>
    <div id="authorDialog1">
        <table class="layui-table" lay-skin="line">
            <tbody>
            <tr>
                <td class="table-member">
                    <div class="member-cell">
                        <div class="member-name ellipsis-1">

                        </div>
                    </div>
                </td>
            </tr>
            </tbody>
        </table>
    </div>
    <div id="authorDialog2">
        <table class="layui-table" lay-skin="line">
            <tbody>
            <tr>

                <td></td>
                <td></td>
                <td class="table-member">
                    <div class="member-cell">
                            <li>
                                <ul class="member-name ellipsis-1">

                                </ul>
                            </li>
                    </div>
                </td>
                <td></td>
            </tr>
            </tbody>
        </table>
    </div>
    <div id="checkDiv" style="padding: 0px 10px">
        <div class="">
            <form id="checkPassForm" class="layui-form mt20" method="post" action="${ctx}/crowdfund/event/checkPass.do">
                <input type="hidden" name="id" value=""/>
                <div class="layui-form-item" style="padding-left: 15%;">
                    <div class="layui-inline">
                        <label class="layui-form-label">活动类型</label>
                        <div class="layui-input-inline" style="width: 250px">
                            <input type="radio" name="eventType" checked="checked" value="0" title="普通活动"
                                   lay-filter="eventType">
                            <input type="radio" name="eventType" value="1" title="高端活动"
                                   lay-filter="eventType">
                        </div>
                    </div>
                </div>

                <div class="layui-form-item" style="padding-left: 15%;">
                    <div class="layui-inline">
                        <label class="layui-form-label">担保金(每人)</label>
                        <div class="layui-input-inline">
                            <input type="number" name="serviceCharge" autocomplete="off" class="layui-input">
                        </div>
                        <label class="layui-form-mid">元</label>
                    </div>
                </div>

                <div class="layui-form-item" style="padding-left: 15%;">
                    <div class="layui-inline">
                        <label class="layui-form-label"></label>
                        <div class="layui-input-inline" style="width: 200px;">
                            注：高端活动担保金后期可退款
                        </div>
                    </div>
                </div>
            </form>

            <form id="checkRefuseForm" class="layui-form mt20" method="post"
                  action="${ctx}/crowdfund/event/checkRefuse.do">
                <input type="hidden" name="id" value=""/>
                <div class="layui-form-item layui-form-text">
                    <label class="layui-form-label">备注<span style="color: red;">*</span></label>
                    <div class="layui-input-block">
                        <textarea name="checkRemark" lay-verify="" style="width: 250px;"
                                  placeholder="请填写审核备注" class="layui-textarea"></textarea>
                    </div>
                </div>
            </form>
        </div>
    </div>
</div>

<script type="text/javascript" src="${ctx}/script/common/list.js"></script>
<script type="text/javascript" src="${ctx}/script/common/table_option.js"></script>
<script type="text/javascript">
    txz.initHeader({
        nav: [{
            name: '众筹主题审核',
            curr: true
        }],
        info: '<span class="f12">共 <b>${page.totalCount}</b> 条记录',
        <%--btns:[{--%>
        <%--name: '添加主题',--%>
        <%--icon: 'add',--%>
        <%--href: '${ctx}/crowdfund/event/view.do'--%>
        <%--}]--%>
    });
    var laytpl = null;
    $(function () {
        var index = null;
        $(".over-tip").mouseover(function () {
            index = txz.openQTip(this);
        }).mouseout(function () {
            layer.close(index);
        });
        layui.use(['laytpl'], function () {
            laytpl = layui.laytpl;
        });

        //加载分页
        loadPageNew({
            elem: 'page_content',
            totalCount: '${page.totalCount}',
            limit: '${page.limit}',
            page: '${page.page}'
        });

        //加载日历
        layui.use(['laytpl', 'laypage', 'laydate', 'form'], function () {
            var laytpl = layui.laytpl, laydate = layui.laydate, laypage = layui.laypage, form = layui.form;
            // element.on('tab(type)', function (data) {
            //     if (data.index == 0) {
            //         $('#status').val(0);
            //         $('#myForm').submit();
            //     }
            //     else if (data.index == 1) {
            //         $('#status').val(1);
            //         $('#myForm').submit();
            //     }
            // });

            // form.verify({
            //     checkRemark:function (value) {
            //         debugger;
            //         if (value.trim() == '') {
            //             return '请填写备注';
            //         }
            //     }
            // });

            // 查询开始日期
            var start = {
                elem: 'input[name=s_start]'
            };

            var end = {
                elem: 'input[name=s_end]'
            };
            laydate.render(start);
            laydate.render(end);

            // 查询发布日期
            var start = {
                elem: 'input[name=createStart]'
            };

            var end = {
                elem: 'input[name=createEnd]'
            };
            laydate.render(start);
            laydate.render(end);
        });

    });

    /**
     * 通过当前主题
     * @param eventId
     */
    function passThisEvent(eventId, partnerType) {

        if (eventId == '' || eventId == undefined || partnerType == undefined) {
            layer.msg('主题参数有误', {
                icon: 2,
                title: '系统提示',
                time: 2000
            });
        } else {
            if (partnerType != 0) {

                $.post("${ctx}/crowdfund/event/checkPass.do", {
                    id: eventId
                }, function (data) {
                    //layer.close(loadIndex);
                    setTimeout(function () {
                        if (data.success == true) {
                            layer.msg('当前主题审核通过', {title: '审核通知', icon: 1, time: 2000}, function () {
                                window.location.reload();
                            });
                        } else {
                            layer.msg('当前主题审核失败', {title: '审核通知', icon: 2, time: 2000});
                        }
                    }, 500);
                })
            } else {
                //审核通过当前主题
                $("#checkDiv #checkPassForm").show();
                $("#checkDiv #checkPassForm [name=id]").val(eventId);
                $("#checkDiv #checkRefuseForm").hide();

                var checkIndex = layer.open({
                    type: 1,
                    area: ['550px', '330px'],
                    title: '审核通过',
                    content: $("#checkDiv"),
                    btn: ['确定', '取消'],
                    yes: function () {
                        var payment = $("#checkDiv #checkPassForm [name=serviceCharge]").val();

                        if (payment != 0 && payment < 0.01) {

                            layer.msg("金额不能少于0.01", {title: '审核通知', icon: 2, time: 2000});
                        } else {
                            // 确定按钮
                            $.post($("#checkDiv #checkPassForm").attr('action'),
                                $("#checkDiv #checkPassForm").serialize(), function (res) {
                                    if (res.success) {
                                        layer.msg('当前主题审核通过', {title: '审核通知', icon: 1, time: 2000}, function () {
                                            window.location.reload();
                                        });
                                    } else {
                                        layer.msg(res.description, {title: '审核通知', icon: 2, time: 2000});
                                    }
                                });
                        }
                    },
                    btn2: function () {//取消按钮
                        layer.close(checkIndex);
                    }
                });
            }
        }
    }

    /**
     * 拒绝当前主题
     * @param eventId
     */
    function refuseThisEvent(eventId) {
        if (eventId == '' || eventId == undefined) {

            layer.msg('主题参数有误', {
                icon: 2,
                title: '系统提示',
                time: 2000
            });
        } else {
            //审核拒绝当前主题
            $("#checkDiv #checkRefuseForm").show();
            $("#checkDiv #checkRefuseForm [name=id]").val(eventId);
            $("#checkDiv #checkPassForm").hide();
            layer.confirm('确定要审核拒绝该主题吗？', {icon: 3, title: '审核拒绝提示'}, function (index) {
                layer.open({
                    type: 1,
                    area: ['400px', '250px'],
                    title: '添加备注',
                    content: $("#checkDiv"),
                    btn: ['确定', '取消'],
                    yes: function () { // 确定按钮
                        var checkRemark = $('[name=checkRemark]').val();
                        if (checkRemark.trim() == '') {
                            layer.msg('请填写审核备注', {time: 2000, icon: 0, title: '系统提示'});
                            return;
                        }
                        $.post($("#checkDiv #checkRefuseForm").attr('action'),
                            $("#checkDiv #checkRefuseForm").serialize(), function (res) {
                                if (res.success) {
                                    layer.msg('当前主题审核拒绝成功', {title: '审核通知', icon: 1, time: 2000}, function () {
                                        window.location.reload();
                                    });
                                } else {
                                    layer.msg('当前主题审核拒绝失败', {title: '审核通知', icon: 2, time: 2000});
                                }
                            });
                    },
                    btn2: function () {// 取消按钮
                        layer.close(index);
                    }
                });
            });
        }
    }

    function showAuthor1(remarks) {
        var setPayIndex = layer.open({
            type: 1,
            area: '400px',
            title: '查看备注',
            content: $("#authorDialog1"),
            btn: ['关闭'],
            success: function () { // 弹出后回调
                if (remarks != null && remarks.length > 0) {
                    $("#authorDialog1").find(".member-name").text(remarks);
                } else {
                    util.layerMsgError("暂无备注");
                }
            },
            end: function () { // 销毁后回调
                $("#authorDialog1").find(".member-name").text('');
            },
            yes: function () { // 确定按钮
                layer.close(setPayIndex);
            }
        });
    }
    function showAuthor2(remarks) {
        if (remarks != null && remarks.length > 0) {
            var setPayIndex = layer.open({
                type: 1,
                area: '400px',
                title: '查看担保金',
                content: $("#authorDialog2"),
                btn: ['关闭'],
                success: function () { // 弹出后回调
                    $("#authorDialog2").find(".member-name").text(remarks + "    元");
                },
                end: function () { // 销毁后回调
                    $("#authorDialog2").find(".member-name").text('');
                },
                yes: function () { // 确定按钮
                    layer.close(setPayIndex);
                }
            });
        } else {
            util.layerMsgError("未设置担保金");
        }
    }
</script>
</body>
</html>